package com.mall.util

import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder
import org.springframework.stereotype.Component

/**
 * 密码工具类，用于密码的加密和验证
 */
@Component
class PasswordUtil {

    private val passwordEncoder = BCryptPasswordEncoder()

    /**
     * 对密码进行加密
     */
    fun hashPassword(password: String): String {
        return passwordEncoder.encode(password)
    }

    /**
     * 验证密码是否匹配
     */
    fun checkPassword(rawPassword: String, encodedPassword: String): Boolean {
        return passwordEncoder.matches(rawPassword, encodedPassword)
    }
}